﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Entity.IRepository.Project;
using Entity.ProjectEnt;
using Logic.Repository.Project;
using ZFine.Code;

namespace ZFine.Application.Project
{
     public class CarTypeApp
    {
        private ICarTypeRepository service = new CarTypeRepository();
        public List<CarTypeEntity> GetList()
        {
            return service.IQueryable().ToList();
        }
        public List<CarTypeEntity> GetList(Expression<Func<CarTypeEntity, bool>> predicate)
        {
            return service.IQueryable(predicate).ToList();
        }
        public List<CarTypeEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<CarTypeEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.Name.Contains(keyword));
            }
            return service.FindList(expression, pagination);
        }
        public List<CarTypeEntity> GetListD(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<CarTypeEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.Name.Contains(keyword));
            }
            return service.FindList(expression, pagination);
        }
        public CarTypeEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }
        public int DeleteForm(string keyValue)
        {
            var local = service.FindEntity(keyValue);
            if (local != null)
            {
                return service.Delete(local);
            }
            else
            {
                return -1;
            }
        }
        public int SubmitForm(CarTypeEntity ServiceEntity, string keyValue)
        {
            var LoginInfo = OperatorProvider.Provider.GetCurrent();
            if (LoginInfo != null)
            {
                if (!string.IsNullOrEmpty(keyValue))
                {
                    ServiceEntity.Modify(keyValue);
                    return service.Update(ServiceEntity);
                }
                else
                {
                    ServiceEntity.Create();
                    return service.Insert(ServiceEntity);
                }
            }
            return -1;
        }
        public int SaveIntoDrafts(CarTypeEntity ServiceEntity, string keyValue)
        {
            var LoginInfo = OperatorProvider.Provider.GetCurrent();
            if (LoginInfo != null)
            {
                if (!string.IsNullOrEmpty(keyValue))
                {
                    ServiceEntity.Modify(keyValue);
                    return service.Update(ServiceEntity);
                }
                else
                {
                    ServiceEntity.Create();
                    return service.Insert(ServiceEntity);
                }
            }
            return -1;
        }
    }
}
